package cn.com.filemanager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 此Servlet不需要URL访问   所以不需要配置 servlet-mapping 访问映射  urlPatterns
 * loadOnStartup 配置加载   启动顺序  值越小 越优先 必须同时配置属性 value 否则无法激活
 * @author zhaokk
 */
@WebServlet( name="InitServlet",loadOnStartup = 1, value="")
public class InitServlet extends HttpServlet {
    @Override
    public void init() throws ServletException {
        Properties properties = new Properties();
        InputStream inStream = null;
        try {
            // 初始化配置文件
            inStream = InitServlet.class.getResourceAsStream("/config.properties");
            properties.load(inStream);

            Set<Map.Entry<Object, Object>> keys = properties.entrySet();
            for (Map.Entry<Object, Object> entry : keys) {
                SystemConfig.getConfig().put(entry.getKey().toString(), entry.getValue().toString());
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
            //throw new ServletException(e);
        }
    }
}
